#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, char const *argv[])
{
    pid_t pid = fork();//错误
    if (pid < 0)
    {
        perror("fork");
        exit(-1);
    }
    else if (pid == 0)//表示子进程
    {
        printf("child: pid=%d\n",getpid());//获取当进程的进程号
        printf("child: pid=%d\n",getppid());//获取父进程的进程号

        while (1)
        {
            printf("child: procrss is running\n");
            sleep(1);
        }
        
    }
    else//表示父进程 pid>0
    {
        printf("parent: pid=%d\n",getpid());//获取当进程的进程号
        printf("parent: pid=%d\n",getppid());//获取父进程的进程号

        while (1)
        {
            printf("parent: procrss is running\n");
            sleep(1);
        }
    }
    
    return 0;
}
